package com.vincent.guava.basics;

import joptsimple.internal.Strings;

import com.google.common.base.Preconditions;

public class PreconditionsTester {

	private Long socialId;
	private String username;
	private String applicationId;
	private String carriername;

	public Long getSocialId() {
		return socialId;
	}

	public void setSocialId(Long socialId) {
		this.socialId = socialId;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getApplicationId() {
		return applicationId;
	}

	public void setApplicationId(String applicationId) {
		this.applicationId = applicationId;
	}

	public String getCarriername() {
		return carriername;
	}

	public void setCarriername(String carriername) {
		this.carriername = carriername;
	}

	protected void before(Long socialId, String username, String carriername,
			String applicationId) {
		if (socialId == null) {
			throw new IllegalArgumentException("id cannot be null");
		}

		if (username == null || username.length() == 0) {
			throw new IllegalArgumentException("firstName cannot be empty");
		}

		if (carriername == null || carriername.length() == 0) {
			throw new IllegalArgumentException("lastName cannot be empty");
		}

		if (applicationId == null || applicationId.length() == 0) {
			throw new IllegalArgumentException("login cannot be empty");
		}
	}

	public void after(Long socialId, String username, String carriername,
			String applicationId) {
		Preconditions.checkNotNull(socialId);
		Preconditions.checkNotNull(username);
		Preconditions.checkNotNull(carriername);
		Preconditions.checkNotNull(applicationId);

		Preconditions.checkArgument(username.length() > 0);
		Preconditions.checkArgument(carriername.length() > 0);
		Preconditions.checkArgument(applicationId.length() > 0);
	}

	public void end(Long socialId, String username, String carriername,
			String applicationId) {
		Preconditions.checkNotNull(socialId, "socialId can not be null!");
		Preconditions.checkArgument(Strings.isNullOrEmpty(username),
				"String can not be null or empty!");
		Preconditions.checkArgument(Strings.isNullOrEmpty(carriername),
				"String can not be null or empty!");
		Preconditions.checkArgument(Strings.isNullOrEmpty(applicationId),
				"String can not be null or empty!");

	}
}
